package org.cedar.syntaxcore;

/**
 * <p>Title: 后缀式（Nipolan）最小单位</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: </p>
 * @author net.wzh
 * @version 1.0
 */
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

 public class ExecutionItem {
  String itemString;
  int itemType;
  int itemOperator;
  List itemParams;
  public ExecutionItem() {
    itemString = "";
    itemType = ItemType.itUnknow;
    itemOperator = EnmOperators.Blank;
    itemParams = null;
  }

  public ExecutionItem(boolean b) {
    itemString = String.valueOf(b);
    itemType = ItemType.itBool;
    itemOperator = EnmOperators.Blank;
    itemParams = null;
  }

  public ExecutionItem(int itType, String s) {
    if(itType == ItemType.itVariable ){
        this.makeVarItem(s);
    }else{
        itemType = itType;
        itemOperator = EnmOperators.Blank;
        itemString = s;
        itemParams = null;
    }
  }

  public ExecutionItem(int op) {
    itemString = String.valueOf(op);
    itemType = ItemType.itOperator;
    itemOperator = op;
    itemParams = null;
  }

  public ExecutionItem(String s, List param) {
    itemString = s;
    itemType = ItemType.itFunction;
    itemOperator = EnmOperators.Blank;
    itemParams = param;
  }

  private void makeVarItem(String s){
      this.itemType = ItemType.itVariable;
      this.itemOperator = EnmOperators.Blank;
      StringTokenizer st = new StringTokenizer(s,",");
      if(st.countTokens() > 1)
          this.itemParams = new ArrayList();
      this.itemString = st.nextToken();
      while(st.hasMoreTokens()){
          this.itemParams.add(st.nextElement());
      }
      st = null;
  }
  public static ExecutionItem getVarItemByVarName(String s){
      ExecutionItem ret = new ExecutionItem();
      ret.itemType = ItemType.itVariable;
      ret.itemOperator = EnmOperators.Blank;
      StringTokenizer st = new StringTokenizer(s,",");
      if(st.countTokens() > 1)
          ret.itemParams = new ArrayList();
      ret.itemString = st.nextToken();
      while(st.hasMoreTokens()){
          ret.itemParams.add(st.nextElement());
      }
      st = null;
      return ret;
  }
  public void destroy(){
      if(null != this.itemParams)
          this.itemParams.clear();
  }
  public String toString(){
	  return this.itemString;
  }
}
